package io.renren.modules.utypeone.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.emp.entity.EmployeeLocationEntity;
import io.renren.modules.utypetwo.entity.Utype2TableEntity;
import io.renren.modules.weldingmachineinfo.entity.WeldingmachineinfoEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.utypeone.entity.Utype1TableEntity;
import io.renren.modules.utypeone.service.Utype1TableService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-09-14 08:47:12
 */
@RestController
@RequestMapping("utypeone/utype1table")
public class Utype1TableController {
    @Autowired
    private Utype1TableService utype1TableService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("utypeone:utype1table:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = utype1TableService.queryPage(params);

        return R.ok().put("page", page);
    }

    //根据label_id删除
    @PostMapping("deleteByLabelId")
    public Integer deleteByLabelId(@RequestParam(value = "cardId",required = false) String cardId){
        return utype1TableService.deleteByLabelId(cardId);
    }


//    @GetMapping("getLabel")
//    public List<Utype1TableEntity> getLabel(@RequestParam(value = "labelId",required = false) String labelId){
//        return utype1TableService.getLabel(labelId);
//    }

    @GetMapping("getLabel")
    public R getLabel(@RequestParam Map<String, Object> params){
        // PageUtils page = employeeService.queryPage(params);
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String key = String.valueOf(params.get("key"));
        Page<Utype1TableEntity> page = new Page<>(pageIndex,pageSize);
        // 通过调用自定义dao层实现
        utype1TableService.getLabel(key,page);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{uuid}")
    @RequiresPermissions("utypeone:utype1table:info")
    public R info(@PathVariable("uuid") String uuid){
		Utype1TableEntity utype1Table = utype1TableService.getById(uuid);

        return R.ok().put("utype1Table", utype1Table);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("utypeone:utype1table:save")
    public R save(@RequestBody Utype1TableEntity utype1Table){
		utype1TableService.save(utype1Table);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("utypeone:utype1table:update")
    public R update(@RequestBody Utype1TableEntity utype1Table){
		utype1TableService.updateById(utype1Table);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("utypeone:utype1table:delete")
    public R delete(@RequestBody String[] uuids){
		utype1TableService.removeByIds(Arrays.asList(uuids));

        return R.ok();
    }

}
